#include <iostream>
#include <string>
#include <unordered_map>
#include <climits>

using namespace std;

// 2516. 每种字符至少取 K 个
// https://leetcode.cn/problems/take-k-of-each-character-from-left-and-right/description/

class Solution1
{
public:
    int takeCharacters(string s, int k)
    {
        int n = s.size();
        if (k * 3 > n)
            return -1;
        if (k == 0)
            return n;
        int left = 0;
        unordered_map<char, int> recordCntOfCh;
        int ans = INT_MAX;
        for (int i = 0; i < n + n; i++)
        {
            char curCh = s[i % n];
            recordCntOfCh[curCh]++;

            while (i >= n - 1 && recordCntOfCh['a'] >= k && recordCntOfCh['b'] >= k && recordCntOfCh['c'] >= k)
            {
                char delCh = s[left % n];
                if (recordCntOfCh[delCh] - 1 < k)
                {
                    break;
                }
                --recordCntOfCh[delCh];
                left++;
            }
            if (i - left < n && (left == 0 || i == n - 1 || (i >= n && left < n)))
            {
                if (recordCntOfCh['a'] >= k && recordCntOfCh['b'] >= k && recordCntOfCh['c'] >= k)
                {
                    ans = min(ans, i - left + 1);
                }
            }
        }
        return ans == INT_MAX ? -1 : ans;
    }
};

class Solution
{
public:
    int takeCharacters(string s, int k)
    {
        if(k == 0){
            return 0;
        }
        int n = s.size();
        unordered_map<char, int> cntCh;
        for (char ch : s)
        {
            cntCh[ch]++;
        }
        if (cntCh['a'] < k || cntCh['b'] < k || cntCh['c'] < k)
        {
            return -1;
        }

        int left = 1;
        int ret = -1;
        
           
    }
};

int main()
{
    return 0;
}